import Vue from 'vue'
import Vuex from 'vuex'
import {getItem,setItem,removeItem} from '@/utils/storage'

Vue.use(Vuex)

const TOKEN_KEY = 'TOUTIAO_USER'

export default new Vuex.Store({
  state: {
    //一个对象，存储当前登录用户信息（token）
    user:getItem(TOKEN_KEY)
    // user:JSON.parse(window.localStorage.getItem(TOKEN_KEY))
  },
  mutations: {
    setUser(state,data){
      state.user = data

      //数据备份到本地存储
      setItem(TOKEN_KEY,state.user)
      // window.localStorage.setItem(TOKEN_KEY,JSON.stringify(state.user))
    }
  },
  actions: {
  },
  getters: {
  },
  modules: {
  }
  
})
